package cn.juni.service.impl;

import cn.juni.dao.IRoleDao;
import cn.juni.pojo.Permission;
import cn.juni.pojo.Role;
import cn.juni.service.IRoleService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * @author Juni
 * @date 2021/2/26
 */
@Service
public class RoleServiceImpl implements IRoleService {

    @Autowired
    IRoleDao roleDao;

    public List<Role> findAllRoles(Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return roleDao.findAllRoles();
    }

    public int insertRole(Role role) {
        role.setId(UUID.randomUUID().toString().replace("-",""));
        return roleDao.insertRole(role);
    }

    public Role findRole(String id) {
        return roleDao.findRole(id);
    }

    public List<Permission> findOtherPermission(String roleId) {
        return roleDao.findOtherPermission(roleId);
    }

    public void inserRolePermission(String roleId, String[] ids) {
        for(String permissionId : ids){
            roleDao.inserRolePermission(roleId,permissionId);
        }
    }
}
